package com.mzx.thread;
//线程停止的方法
public class TestStop implements Runnable {
    private Boolean flag=true;
    @Override
    public void run() {
        int i=0;
        while (flag){
            System.out.println("run....Thread"+i++);
        }
    }
    //2.设置一个公开方法停止线程，转换标志位
    public void stop(){
        this.flag=false;
    }

    public static void main(String[] args) {
        TestStop threadA = new TestStop();
        new Thread(threadA).start();
//        TestStop threadA = new TestStop();
//        new Thread(threadA).start();

        for (int i = 0; i < 1000; i++) {
            System.out.println(" main"+i);
            if (i==100){
                //当i==100时，threadA线程（子线程）停止，主线程执行到结束
                threadA.stop();
                System.out.println("该线程停止了");
            }

        }



    }






}
